<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="__ASSETS__/images/favicon.png" type="image/png">

    <title>{if condition="$action eq 'add'"}添加{else/}编辑{/if}{$title}</title>

    <link rel="stylesheet" href="__ASSETS__/css/style.default.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/validform.css?">
    <link rel="stylesheet" type="text/css" href="__STATIC__/Fileinput/css/fileinput.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/sweetalert/css/sweetalert.css">

</head>

<body>
<div id="preloader">
    <div id="status"><i class="fa fa-spinner fa-spin"></i></div>
</div>
<section>
    {include file='public_sidebar'}<!-- leftpanel -->
    <div class="mainpanel">
        {include file='public_header'}<!-- headerbar -->
        <div class="pageheader">
            <h2><i class="fa fa-home"></i>{if condition="$action eq 'add'"}添加{else/}编辑{/if}{$title}<span>欢迎光临平台...</span></h2>
            <div class="breadcrumb-wrapper">
                <span class="label">您现在的位置:</span>
                <ol class="breadcrumb">
                    <li>平台首页</li>
                    <li>{$title}管理</li>
                    <li class="active">{if condition="$action eq 'add'"}添加{else/}编辑{/if}{$title}</li>
                </ol>
            </div>
        </div>

        <div class="contentpanel">
            <div class="panel panel-default">

                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="panel-close">&times;</a>
                        <a href="" class="minimize">&minus;</a>
                    </div>
                    <h4 class="panel-title">{if condition="$action eq 'add'"}添加{else/}编辑{/if}{$title}</h4>
                </div>

                <div class="panel-body panel-body-nopadding">
                    <form action="" method="post" class="form-horizontal form-bordered" enctype="multipart/form-data" id="myupload">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">新闻标题</label>
                            <div class="col-sm-6">
                                <input class="form-control" name="title"
                                       datatype="*" nullmsg="请输入新闻标题！" placeholder="请输入新闻标题！"
                                       value="{present name='$data.title'}{$data.title}{/present}"
                                />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">新闻图片：</label>
                            <div class="col-sm-6">
                                <input id="filepicurl" type="file" multiple>
                                {if !empty($data.news_slave)}
                                {volist name="data.news_slave" id="vop"}
                                <input type="hidden" value="{$vop.img_url}" name="picimage[]" >
                                {/volist}
                                {/if}
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">期号</label>
                            <div class="col-sm-2">
                                <input  class="form-control" type="text" name="expect" datatype="n"
                                        nullmsg="请输入当前报纸期号！" placeholder="请输入当前报纸期号！"
                                        value="{present name='$data.expect'}{$data.expect}{/present}"
                                />
                            </div>
                        </div>

                        <div class="panel-footer">
                            <div class="row">
                                <div class="col-sm-6 col-sm-offset-3">
                                    {present name='$data.id'}<input type="hidden" name="id" value="{$data.id}">{/present}
                                    <input type="submit" id="form-submit" value="提交" class="btn btn-primary"/>
                                    <button class="btn btn-default" onclick="javascript:history.back(-1)">返回</button>
                                </div>
                            </div>
                        </div><!-- panel-footer -->

                    </form>
                </div><!-- panel-body -->
            </div><!-- panel -->
        </div><!-- contentpanel -->
    </div><!-- mainpanel -->
</section>
<script src="__ASSETS__/js/jquery-1.11.1.min.js"></script>
<script src="__ASSETS__/js/jquery-migrate-1.2.1.min.js"></script>
<script src="__ASSETS__/js/jquery-ui-1.10.3.min.js"></script>
<script src="__ASSETS__/js/bootstrap.min.js"></script>
<script src="__ASSETS__/js/modernizr.min.js"></script>
<script src="__ASSETS__/js/jquery.sparkline.min.js"></script>
<script src="__ASSETS__/js/toggles.min.js"></script>
<script src="__ASSETS__/js/retina.min.js"></script>
<script src="__ASSETS__/js/jquery.cookies.js"></script>


<script src="__ASSETS__/js/jquery.autogrow-textarea.js"></script>
<script src="__ASSETS__/js/bootstrap-timepicker.min.js"></script>
<script src="__ASSETS__/js/jquery.maskedinput.min.js"></script>
<script src="__ASSETS__/js/jquery.tagsinput.min.js"></script>
<script src="__ASSETS__/js/jquery.mousewheel.js"></script>
<script src="__ASSETS__/js/custom.js"></script>
<!-- 时间 -->
<script src='__PUBLIC__/datepicker/WdatePicker.js' type='text/javascript'></script>
<!-- 文件上传 -->
<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>
<!-- JQ验证 -->
<script src="__PUBLIC__/js/Validform_v5.3.2_min.js"></script>
<!-- 编辑器 -->
<script type="text/javascript" charset="utf-8" src="__EDITOR__/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__EDITOR__/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__EDITOR__/lang/zh-cn/zh-cn.js"></script>
<!-- 图片上传 -->
<script src="__STATIC__/Fileinput/js/fileinput.js"></script>
<script src="__STATIC__/Fileinput/js/plugins/canvas-to-blob.js"></script>
<script src="__STATIC__/Fileinput/js/plugins/purify.js"></script>
<script src="__STATIC__/Fileinput/js/plugins/sortable.js"></script>
<!-- 弹窗 -->
<script src="__STATIC__/sweetalert/js/sweetalert.min.js"></script>


<script type="text/javascript">
    $(function(){
        fileinputMore('filepicurl','picimage[]','picarr[]');
        $("#myupload").Validform();  //就这一行代码！;
    });
</script>

<script type="text/javascript">
    //组图上传
    function fileinputMore(fileid, picurlname, field) {
        var widths = arguments[3] ? arguments[3] : '180px';//设置默认的图片宽度
        var heights = arguments[4] ? arguments[4] : '160px';//设置默认的图片高度
        //组图上传
        var $input = $("#" + fileid);
        var $picimg = $("input[name='" + picurlname + "']");

        var $Preview = [];
        var $Config = [];
        $picimg.each(function (i, e) {
            $Preview.push("<img class='kv-preview-data file-preview-image' style='width:" + widths + ";height:" + heights + ";' src='" + $(this).val() + "'>");
            $Config.push({
                caption: $(this).attr('flag'),
                show: $(this).attr('show'),
                size: 0,
                url: "<input type='hidden' required name='" + field + "' value='" + $(this).val() + "'>",
                key: i
            });

        });

        var footerTemplate = '<div class="file-thumbnail-footer">\n' +
            '   <div style="margin:5px 0">\n' +
            '   </div>\n' +
            '   <button type="button" class="kv-file-forward text-info header-left" title="前移"><i class="glyphicon glyphicon-chevron-left"></i></button>\n' +
            '   &nbsp;{size}&nbsp;\n' +
            '   <button type="button" class="kv-file-backward text-danger header-right" title="后移"><i class="glyphicon glyphicon-chevron-right"></i></button>\n' +
            '   {actions}\n' +
            '</div>';

        $input.fileinput({
            uploadUrl: "{:url('console/Uploads/upload',['type'=>'news'])}",
            deleteUrl: "{:url('console/Uploads/updel')}",
            overwriteInitial: false,
            layoutTemplates: {footer: footerTemplate, size: '<samp><small>({sizeText})</small></samp>'},
            initialPreview: $Preview,
            initialPreviewConfig: $Config,

        }).on("filebatchselected", function (event, files) {
            if($('button[type="submit"]')[0]){
                $('button[type="submit"]').attr('disabled','disabled')
            }
            if($('input[type="submit"]')[0]){

                $('input[type="submit"]').attr('disabled','disabled')
            }
            $input.fileinput("upload");//选择后自动上传
        }).on('fileuploaded', function (event, data, previewId, index) {
            var dataObj = eval("(" + data.response + ")");
            if (dataObj['code'] == 0) {
                $('#' + previewId).append("<input type='hidden' name='" + field + "' value='" + dataObj['img'] + "'>");
                if($('button[type="submit"]')[0]){
                    $('button[type="submit"]').removeAttr('disabled')
                }
                if($('input[type="submit"]')[0]){

                    $('input[type="submit"]').removeAttr('disabled')
                }
            }
            else {
                swal("出错了", "上传失败,请刷新再试", "error");
            }
        });
    }

</script>
</body>
</html>
